//年-月-日
export function dateYMD(val) {
  let d = dateTime(val);

  return `${d.year}-${d.month}-${d.date}`;
}
//月-日
export function dateZMD(val) {
  let d = dateTime(val);

  return `${d.month}-${d.date}`;
}
//英文月份+年
export function dateYM(val, stamp = "") {
  let d = dateTime(val);
  return `${d.simpleMonthStr}${stamp} ${d.year}`;
}
//英文月份+日
export function dateMD(val, stamp = "") {
  let d = dateTime(val);
  return `${d.simpleMonthStr}${stamp} ${d.date}`;
}
//时：分：秒
export function dateHMS(val) {
  let d = dateTime(val);

  return `${d.hour}:${d.minutes}:${d.seconds}`;
}
//时：分
export function dateZHM(val) {
  let d = dateTime(val);

  return `${d.hour}:${d.minutes}`;
}
//时：分 PM/AM
export function dateHM(val) {
  let d = dateTime(val);

  return `${d.hour}:${d.minutes} ${d.unit}`;
}
//年-月-日 时：分：秒
export function getDate(val) {
  if (!val) return "";

  val *= 1;

  return `${dateYMD(val)}  ${dateHMS(val)}`;
}
//修补 +0
export function repaireZero(val) {
  val *= 1;

  return val > 9 ? val : "0" + val;
}
export function dateTime(val) {
  let d = new Date(val);
  let year = d.getFullYear();
  let month = d.getMonth();
  let date = d.getDate();
  let hour = d.getHours();
  let minutes = d.getMinutes();
  let seconds = d.getSeconds();
  let unit = hour >= 12 ? "PM" : "AM";
  let monthes = [
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December"
  ];
  return {
    year,
    month: repaireZero(month + 1),
    fullMonthStr: monthes[month],
    simpleMonthStr: monthes[month].slice(0, 3),
    date: repaireZero(date),
    hour: repaireZero(hour),
    minutes: repaireZero(minutes),
    seconds: repaireZero(seconds),
    unit
  };
}
